﻿using WJ.Infrastructure.Util;

namespace WJ.Infrastructure.WeChat
{
    public class Config
    {
        /// <summary>
        /// 小程序appid
        /// </summary>
        public static string WeAppId { get; }

        /// <summary>
        /// 小程序appsecret
        /// </summary>
        public static string WeAppSecret { get; }

        /// <summary>
        /// 网站appid
        /// </summary>
        public static string WebAppId { get; }

        /// <summary>
        /// 网站appsecret
        /// </summary>
        public static string WebAppSecret { get; }

        /// <summary>
        /// 商户号
        /// </summary>
        public static string MchId { get; }

        /// <summary>
        /// 商户密钥
        /// </summary>
        public static string MchKey { get; }

        /// <summary>
        /// 支付回调地址
        /// </summary>
        public static string NotifyUrl { get; }

        static Config()
        {
            WeAppId = ConfigUtil.GetConfig("WeAppId");
            WeAppSecret = ConfigUtil.GetConfig("WeAppSecret");

            WebAppId = ConfigUtil.GetConfig("WebAppId");
            WebAppSecret = ConfigUtil.GetConfig("WebAppSecret");

            MchId = ConfigUtil.GetConfig("WeChatMchId");
            MchKey = ConfigUtil.GetConfig("WeChatMchKey");
            NotifyUrl = ConfigUtil.GetConfig("WechatNotifyUrl");
        }

        public static AppConfig GetAppConfig(LoginType type)
        {
            AppConfig appConfig = new AppConfig
            {
                AppId = "",
                AppSecret = ""
            };

            if (type == LoginType.WeApp)
            {
                appConfig.AppId = WeAppId;
                appConfig.AppSecret = WeAppSecret;
            }
            else if (type == LoginType.MWEB)
            {
                appConfig.AppId = WebAppId;
                appConfig.AppSecret = WebAppSecret;
            }

            return appConfig;
        }
    }

    public class AppConfig
    {
        public string AppId { get; set; }

        public string AppSecret { get; set; }
    }
}